﻿namespace Example
{
    using Xunit;

    public sealed class DelegateFacts
    {
        public delegate int MyDelegate(int a, int b);

        public static int Add(int a, int b)
        {
            return a + b;
        }

        public static int CallDelegate(MyDelegate func, int a, int b)
        {
            return func(a, b);
        }

        [Fact]
        public void assign_and_call()
        {
            MyDelegate func = Add;

            const int expected = 3;
            var actual = func(1, 2);

            Assert.Equal(expected, actual);
        }

        [Fact]
        public void pass_as_parameter()
        {
            MyDelegate func = Add;

            const int expected = 3;
            var actual = CallDelegate(func, 1, 2);

            Assert.Equal(expected, actual);
        }
    }
}